home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
PGM_TOOL
/
PARAMS
/
CONFIG.DOC
< prev
next >
Wrap
Text File
|
1992-02-26
|
9KB
|
213 lines
CONFIG Program Documentation
The program CONFIG is a general-purpose configuration program that
can change the configuration (default options) of a named target file
(an .exe program) to specified options. The target program must use
a compatible method. Two sections follow, describing first the use
of the CONFIG program, and second, how to write a program that will
be reconfigurable by CONFIG.
----------------------------------------------------------------------
Using the CONFIG Program
A summary of the usage of the CONFIG program is displayed if the
CONFIG program is run with less than two command-line parameters:
CONFIG (c) 2-12-92 J. M. Clark
Reconfigures a target program with given options.
Usage: config TargetPath Options [ +s ]
Example: config c:\bin\target /c+/b-/a12/xname
The parameters may be in any order.
TargetPath is the program filename minus the final '.exe'.
Options is one parameter beginning with '/'.
Use '+s' to retain the backup (.ex$) file.
Messages report reconfiguration success or failure.
Run the target program with option '/?'
to check that the options are appropriate.
In the above example, the default options of the program file
c:\bin\target.exe are changed to /c+ /b- /a12 and /xname. Note
that the '.exe' extension must not be included on the CONFIG
command line, and that no spaces may appear between the options.
Note also that the CONFIG program has no way of determining if
the given options are appropriate for the target program. It
is suggested to run the target program with option '/?' to check
the options; the next section discusses this further.
The CONFIG program replaces ALL of the default options of the target
program with the given options. (That is, all options that are
reconfigurable by the CONFIG method.) The result of omitting options
in the CONFIG command line is discussed in the section "Making a
Program Reconfigurable".
The +s option causes the original target file to be saved with a ".ex$"
extension. Normally, the backup ".ex$" file is used temporarily while
converting the target file, then automatically deleted.
The following messages may be displayed by CONFIG. Futher explanations
are given here. The given target pathname is represented by +FName+
in this list.
Cannot find target file "+FName+.exe".
If a name like "target.exe.exe" is reported, the name "target.exe"
was given on the command line, and the CONFIG program added another
".exe"; do not include the ".exe" on the CONFIG command line.
Otherwise, check that a correct directory path prefixes the program
filename.
Could not locate target data.
Typically, this indicates that the target program does not use
the CONFIG method for reconfiguration. (See next section.)
Source data is too long for target.
The CONFIG program detects the length of the configuration data
space in the target program file, and measures the length of
the source data (the options parameter string from the command
line). This message indicates that the target program does not
have sufficient space for the given options.
Could not change target.
This can happen only if the target program is faulty.
Could not finish rewriting target.
This can happen if there is insufficient disk space for the old
(backup) and new copies of the target file.
Reconfiguration completed.
So far, so good. But run the target program with the /? option
so that it can check that the new options are understood.
Original target is now named +FName+.ex$
New (bad?) target is now named +FName+.exe
Try: fc /b +FName+.ex$ +FName+.exe
This message appears when the target file is found, any error
is detected, and the +s option WAS specified. However, for most
errors, the new file is an unchanged copy of the original. It
is suggested that the FC (File Compare) program may be used to
determine if the old and new files differ. For the "could not
finish rewriting" error, the new file is probably smaller than
the original file.
Original target file is unchanged.
This message appears when the target file is found, any error
is detected, and the +s option was NOT specified. In this case,
the new file is deleted and the backup file is renamed as the
original.
----------------------------------------------------------------------
Making a Program Reconfigurable
The following Turbo Pascal program illustrates a method of initializing
the default options of a program so that they can be reconfigured by
the CONFIG program. It can be used to test the CONFIG program.
For further details of the method, see the Skel.pas program, discussed
later.
program target; {test}
type
tConfig = record
magic: string[10];
cdata: string[20];
end;
const
Config: tConfig = (
magic: '!)@(#*$&%^';
cdata: '/c+/d-/e12//////////'
);
begin
writeln(Config.cdata);
end.
Other programming languages can also be used, but the tConfig record
structure must remain the same. If using another language, check that
the compiler generates strings prefixed by a length byte, and that the
"cdata" string immediately follows the "magic" string in the .exe file.
The CONFIG program searches the target .exe file for the "magic" string,
which gives the location of the "cdata" string. The length byte that
preceeds the cdata string indicates how much data space is available.
The '/////////' padding after the actual data is used to reserve space
for configuration changes. For this reason, '//' is defined as a
special "option" that terminates the actual data.
In the target program, four stages of option definition can be
supported:
(1) Ordinary initialization of option variables.
(2) Change these options according to the data installed by
the CONFIG program.
(3) Optionally, read options from an environment variable
or from an options file.
(4) Get options from the command line; these can change
between filenames.
At any stage after stage 1, if any option data is not specified, the
option values default to those set at an earlier stage.
Note that using CONFIG avoids using up scarce environment space, and
eliminates the bother of setting up and locating an options file,
although it may be preferred to also use an options file if there is
a large amount of option data. If an option file is necessary, CONFIG
can define its pathname.
The Skel.pas program is a "skeleton" program that outlines the code
needed to initialize a program and then control it from the command
line. The user (programmer) fills in application-dependant details.
The Skel.pas program uses the Params unit. The Params unit defines
a ScanPars procedure that scans the command line and interprets it.
The ScanPars procedure calls a ParseOpts procedure to collect option
data from parameters that begin with a '/', and calls a user-defined
DoFile procedure for the other parameters. The ParseOpts procedure
calls a user-defined SetOpts procedure that interprets the options.
But before the command line is interpreted (stage 4), the program
calls the ParseOpts procedure to scan the Config.cdata (stage 2),
using the same interpretation as for the command line. Here is the
basic calling hierarchy:
program *
|
2 .-----------. 4
| |
| ScanPars
| |
| .-----------------.
| | |
ParseOpts DoFile *
|
|
SetOpt *
The '2' and '4' indicate stages 2 and 4. The procedures marked '*'
are user-defined. The user program also includes a ShowUsage procedure
to explain the options and also to report the default option values.
The Params unit also provides procedures ShowDefault, RptError, and
ChkFlg, and functions GetInt and GetBool to support the user-defined
routines.
The Params unit initializes the variable ParNo to = -1, but when
ParseOpts is called by ScanPars, ParNo is used to index the command-
line parameters ("for ParNo:= 1 to ParamCount do .."). Thus, for any
options that are to be changable only in stage 2 (not stage 4), SetOpt
can use the condition "if ParNo < 0". If needed, ParNo = 0 can be used
to indicate stage 3.